/**
 * 
 */
package com.postek.coyote.postekwifi;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import com.postek.cdf.CDFPTKAndroid;
import com.postek.coyote.postekwifi.bean.LabelBean;
import com.postek.coyote.postekwifi.bean.MXBean;

import java.util.ArrayList;

/**
 * @author yrwang
 *
 */
public class PrintMXActivity extends AppCompatActivity {

	private CDFPTKAndroid cdf = MainActivity.cdf;
	private ArrayList<LabelBean> labelBeans = MainActivity.labelBeans;
	
	private Button btnPrint = null;
	private Button btnCancel = null;
	
	private EditText et_MX1 = null;
	private EditText et_MX2 = null;
	private Spinner sp_MX3 = null;
	private Spinner sp_MX4 = null;
	private EditText et_MXS = null;
	private EditText et_print_number=null;
	private EditText et_print_cpnumber=null;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.print_mx);
		
		btnPrint = (Button) findViewById(R.id.btn_printMX_print);
		btnCancel = (Button) findViewById(R.id.btn_printMX_cancel);
		
		et_MX1 = (EditText) findViewById(R.id.et_print_MX1);
		et_MX2 = (EditText) findViewById(R.id.et_print_MX2);
		sp_MX3 = (Spinner) findViewById(R.id.sp_print_MX3);
		sp_MX4 = (Spinner) findViewById(R.id.sp_print_MX4);
		et_MXS = (EditText) findViewById(R.id.et_print_MXS);
		et_print_number= (EditText) findViewById(R.id.et_print_number);
		et_print_cpnumber= (EditText) findViewById(R.id.et_print_cpnumber);
		
		btnCancel.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		
		btnPrint.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				int iMX1 = 0;
				int iMX2 = 0;
				int iMX3 = sp_MX3.getSelectedItemPosition() + 2;
				int iMX4 = sp_MX4.getSelectedItemPosition();
				int number=Integer.parseInt(et_print_number.getText().toString());
				int cpnumber=Integer.parseInt(et_print_cpnumber.getText().toString());
				String iMXS = et_MXS.getText().toString();
				
				if(!("".equals(et_MX1.getText().toString()))){
					iMX1 = Integer.parseInt(et_MX1.getText().toString());
				}
				
				if(!("".equals(et_MX2.getText().toString()))){
					iMX2 = Integer.parseInt(et_MX2.getText().toString());
				}
				
				int nReturn = cdf.PTK_DrawBar2D_MaxiCode(iMX1, iMX2, iMX3, iMX4, iMXS);
			
				if (nReturn == 0) {
					MXBean bean = new MXBean(iMX1, iMX2, iMX3, iMX4, iMXS);
					labelBeans.add(bean);
					Toast.makeText(PrintMXActivity.this,  R.string.setting_success, Toast.LENGTH_SHORT).show();
					finish();
				} else {
					Toast.makeText(PrintMXActivity.this,  R.string.setting_fail, Toast.LENGTH_SHORT).show();
				}
			}
		});
	}
	
}
